package nio.channel;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
//输入
public class channelDemo_2 {
    public static void main(String[] args) throws IOException {
        //创建输入流
        File file = new File("1.txt");
        FileInputStream fileInputStream = new FileInputStream(file);

        FileChannel channel = fileInputStream.getChannel();

        ByteBuffer byteBuffer = ByteBuffer.allocate((int) file.length());

        channel.read(byteBuffer);

        byte[] array = byteBuffer.array();
        System.out.println(new String(array));

        channel.close();

    }

}
